package org.NooLab.itexx.storage.docsom;

import java.util.ArrayList;

import org.NooLab.itexx.storage.docsom.iciql.Randomdocuments;
 
import org.NooLab.utilities.strings.ArrUtilities;



/**
 * 
 * 
 * could be more elegant... via reflection...
 *
 */
public class IciqlHandler {
	
	Randomdocuments c;
	//Contexts c;
	String valueListStr ="";
	ArrayList<Double> valueList = new ArrayList<Double>();
	
	public IciqlHandler( ){
		
	}

	public void clearDocHisto( Randomdocuments c) {
		c.clear();
		valueListStr ="";
		valueList.clear() ;
	}
	
	public Randomdocuments finalizeIciql(){
		
		valueListStr = ArrUtilities.arr2Text(valueList , 7, ";") ;
		c.randomdoc = valueListStr ;
		return c;
	}

	/*
					  id             IDENTITY PRIMARY KEY,
					  somid          BIGINT, 
					  docid          BIGINT, 

					  markovid       BIGINT,       ** not yet used, will link a markov description to the histogram description;
					                                  the final SOM data table will be created on the fly **
					  nodesizetotal  INT,	
                      
                      ** describing the uniqueness of the doc **                           
					  docnvariety    DOUBLE ,      ** avg of the number of different docs in the nodes where we found the doc of the record ; **
                      docnvarivar    DOUBLE ,      ** variance of that number **

					  docpvariety    DOUBLE ,      ** avg of the proportion the doc of the record takes in the nodes where it is found; **
				      docpvarivar    DOUBLE ,      ** variance of that number ** 

                      docabundance   DOUBLE ,      ** describes the probability to find this doc in a particular node
                                                      normalized by its length **
                        
					  histogramsize  INT ,
					   
					  createtime     BIGINT,       ** a timestamp, **               
					  status         INT,          **   ** 
					  vanishtime     BIGINT,       ** time when it was noticed that the document is missing  **      
					  
					  Randomdocs  VARCHAR(2000) ** the random context, stored as a list of numerical strings [ ; ] ; 
					                                  it could be of variable length, thus we use a VARCHAR list 
					                                  this is the important part of the table **
		
	 */
	
	public void setContextArgument( String colname, String strval) {
	}

	public void setContextArgument( String colname, long index) {
		
		if (colname.contentEquals("id")){       c.id = index; return; }
		if (colname.contentEquals("docid")){    c.docid = index ; return; }
		if (colname.contentEquals("somid")){    c.somid = index ; return; }
		if (colname.contentEquals("markovid")){ c.markovid = index; return; }
		if (colname.contentEquals("vanishtime")){ c.vanishtime = index ; return; }
		if (colname.contentEquals("createtime")){ c.createtime = index ; return; }
	}
	public void setContextArgument( String colname, int val) {

		if (colname.contentEquals("histogramsize")){  c.histogramsize = val ; return; }
		if (colname.contentEquals("nodesizetotal")){  c.nodesizetotal = val ; return; }
		if (colname.contentEquals("status")){       c.status = val ;}
	}
	
	
	public void setContextArgument( String colname, double numval) {

		try{

			
			if (colname.contentEquals("docnvariety")){  c.docnvariety = numval ; return; }
			if (colname.contentEquals("docnvarivar")){  c.docnvarivar = numval ; return; }
			if (colname.contentEquals("docpvariety")){  c.docpvariety = numval ; return; }
			if (colname.contentEquals("docpvarivar")){  c.docpvarivar = numval ; return; }
			if (colname.contentEquals("docabundance")){ c.docabundance = numval ; return; }

		}catch(Exception e){
			
			int ival = (int) Math.round(numval) ;
			setContextArgument( colname, ival) ;
		}

	}

	public void setContextProfileValue( int cix, int vcix, double numval) {
		valueList.add(numval) ;
	}

	
	public void setDocHistoObj(Randomdocuments ctxt) {
 
		c = ctxt ;
	}

	
	
	
}
